<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="80%" destroy-on-close @closed="$emit('closed')" :close-on-click-modal="false">
        <el-container>
			<el-header>
                <div class="right-panel-search">
                    <div class="search-input">设备名称</div>
                    <el-input v-model="search.title_keywords" placeholder="请输入设备名称" clearable></el-input>
                    <div class="search-input">设备位置</div>
                    <el-select v-model="search.position_id"  filterable  placeholder="请选择设备类别" clearable>
                        <el-option v-for="item in position" :key="item.id" :label="item.title" :value="item.id"/>
                    </el-select>
                    <div class="search-input">设备类别</div>
                    <el-select v-model="search.class_id"  filterable  placeholder="请选择设备类别" clearable>
                        <el-option v-for="item in type" :key="item.id" :label="item.title" :value="item.id"/>
                    </el-select>
                    <div class="search-input">模糊查询</div>
                    <el-input v-model="search.keywords" placeholder="请输入关键词" clearable></el-input>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
                </div>
            </el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" @selection-change="selectionChange"  stripe remoteSort remoteFilter height="400" border :params="query">
					<el-table-column type="selection" width="50" align="center"></el-table-column>
                    <el-table-column prop="code" label="设备编号" align="center"></el-table-column>
                    <el-table-column prop="title" label="设备名称" align="center"></el-table-column>
                    <el-table-column prop="spec" label="设备规格" align="center"></el-table-column>
                    <el-table-column prop="state_title" label="设备状态" align="center"></el-table-column>
                    <el-table-column prop="class_title" label="设备类别" align="center"></el-table-column>
                    <!-- <el-table-column prop="staff_id" label="车间" align="center"></el-table-column> -->
                    <!-- <el-table-column prop="line" label="产线" align="center"></el-table-column> -->
                    <el-table-column prop="staff_id" label="负责人" align="center"></el-table-column>
					<el-table-column prop="create_time" label="创建时间" align="center"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="back">确 定</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
    props:{
        query: { type: String, default: "" },
    },
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择设备',
			},
			visible: false,
			isSaveing: false,
            apiObj: this.$API.device.deviceList.getList,
            selection:[],
            search: {
				keywords: null,
                position_id:null,
                class_id:null,
                title_keywords:null
			},
            position:[],
            type:[],
		}
	},
	mounted() {
        this.getPosition()
        this.getType()
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        submit(){
            this.visible = false
        },
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        selectionChange(selection) {
			this.selection = selection;
		},
        back(){
            this.$emit('success', this.selection)
            this.visible = false;
        },
        // 设备位置
        async getPosition(){
            var res = await this.$API.all.getPosition.get({is_page:0});
            this.position = res.data
        },
        // 设备类别
        async getType(){
            var res = await this.$API.all.getDeviceClass.get({is_page:0});
            this.type = res.data
        },
	}
}
</script>

<style></style>
